using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VFSGROE
    {
        public DataRow Convert2FSGROE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryFSGROE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["FSGMANDANT"] = " ".PadRight(2 ); 
         dwReturn["FSGART"] = " ".PadRight(20 ); 
         dwReturn["FSGVAR"] = " ".PadRight(2 ); 
         dwReturn["FSGGROE"] = " ".PadRight(7 ); 
         dwReturn["FSGAENZL"] = " ".PadRight(0 ); 
         dwReturn["FSGAENB"] = " ".PadRight(8 ); 
         dwReturn["FSGAEND"] = " ".PadRight(0 ); 
         dwReturn["FSGNEUB"] = " ".PadRight(8 ); 
         dwReturn["FSGNEUD"] = " ".PadRight(0 ); 
         dwReturn["FSGABEZ"] = " ".PadRight(40 ); 
         dwReturn["FSGLAENGE"] = " ".PadRight(0 ); 
         dwReturn["FSGLAEME"] = " ".PadRight(3 ); 
         dwReturn["FSGLAEGRP"] = " ".PadRight(1 ); 
         dwReturn["FSGLAEFKT"] = " ".PadRight(12 ); 
         dwReturn["FSGBREITE"] = " ".PadRight(0 ); 
         dwReturn["FSGBRTME"] = " ".PadRight(3 ); 
         dwReturn["FSGBRTGRP"] = " ".PadRight(1 ); 
         dwReturn["FSGBRTFKT"] = " ".PadRight(12 ); 
         dwReturn["FSGHOEHE"] = " ".PadRight(0 ); 
         dwReturn["FSGHOEME"] = " ".PadRight(3 ); 
         dwReturn["FSGHOEGRP"] = " ".PadRight(1 ); 
         dwReturn["FSGHOEFKT"] = " ".PadRight(12 ); 
         dwReturn["FSGGEW"] = " ".PadRight(0 ); 
         dwReturn["FSGGEWME"] = " ".PadRight(3 ); 
         dwReturn["FSGGEWGRP"] = " ".PadRight(1 ); 
         dwReturn["FSGGEWFKT"] = " ".PadRight(12 ); 
         dwReturn["FSGMEGME"] = " ".PadRight(3 ); 
         dwReturn["FSGMEGGRP"] = " ".PadRight(1 ); 
         dwReturn["FSGMEGFKT"] = " ".PadRight(12 ); 
         dwReturn["FSGVOL"] = " ".PadRight(0 ); 
         dwReturn["FSGPRGRP"] = " ".PadRight(1 ); 
         dwReturn["FSGGRLAUF"] = " ".PadRight(1 ); 
         dwReturn["FSGZSFORM"] = " ".PadRight(10 ); 
         dwReturn["FSGARTKZ"] = " ".PadRight(1 ); 
         dwReturn["FSGFILLER"] = " ".PadRight(40 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapFSGROE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveFSGROE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFSGROE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFSGROE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertFSGROE(dwLocal, ITXDBVERSION);
            }
            UpdateFSGROE(dwLocal);
        }
        public void InsertFSGROE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO FSGROE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryFSGROE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FSGROE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM FSGROE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FSGROE";
            Return = Result;
            return Return;
        }
        public void DeleteFSGROE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM FSGROE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateFSGROE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE FSGROE SET "
                    +"FSGMANDANT= :FSGMANDANT,"
                    +"FSGART= :FSGART,"
                    +"FSGVAR= :FSGVAR,"
                    +"FSGGROE= :FSGGROE,"
                    +"FSGAENZL= :FSGAENZL,"
                    +"FSGAENB= :FSGAENB,"
                    +"FSGAEND= :FSGAEND,"
                    +"FSGNEUB= :FSGNEUB,"
                    +"FSGNEUD= :FSGNEUD,"
                    +"FSGABEZ= :FSGABEZ,"
                    +"FSGLAENGE= :FSGLAENGE,"
                    +"FSGLAEME= :FSGLAEME,"
                    +"FSGLAEGRP= :FSGLAEGRP,"
                    +"FSGLAEFKT= :FSGLAEFKT,"
                    +"FSGBREITE= :FSGBREITE,"
                    +"FSGBRTME= :FSGBRTME,"
                    +"FSGBRTGRP= :FSGBRTGRP,"
                    +"FSGBRTFKT= :FSGBRTFKT,"
                    +"FSGHOEHE= :FSGHOEHE,"
                    +"FSGHOEME= :FSGHOEME,"
                    +"FSGHOEGRP= :FSGHOEGRP,"
                    +"FSGHOEFKT= :FSGHOEFKT,"
                    +"FSGGEW= :FSGGEW,"
                    +"FSGGEWME= :FSGGEWME,"
                    +"FSGGEWGRP= :FSGGEWGRP,"
                    +"FSGGEWFKT= :FSGGEWFKT,"
                    +"FSGMEGME= :FSGMEGME,"
                    +"FSGMEGGRP= :FSGMEGGRP,"
                    +"FSGMEGFKT= :FSGMEGFKT,"
                    +"FSGVOL= :FSGVOL,"
                    +"FSGPRGRP= :FSGPRGRP,"
                    +"FSGGRLAUF= :FSGGRLAUF,"
                    +"FSGZSFORM= :FSGZSFORM,"
                    +"FSGARTKZ= :FSGARTKZ,"
                    +"FSGFILLER= :FSGFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("FSGMANDANT", OracleType.NVarChar).Value = dwData["FSGMANDANT"].ToString(); 
          or1.Parameters.Add("FSGART", OracleType.NVarChar).Value = dwData["FSGART"].ToString(); 
          or1.Parameters.Add("FSGVAR", OracleType.NVarChar).Value = dwData["FSGVAR"].ToString(); 
          or1.Parameters.Add("FSGGROE", OracleType.NVarChar).Value = dwData["FSGGROE"].ToString(); 
          or1.Parameters.Add("FSGAENZL", OracleType.NVarChar).Value = dwData["FSGAENZL"].ToString(); 
          or1.Parameters.Add("FSGAENB", OracleType.NVarChar).Value = dwData["FSGAENB"].ToString(); 
          or1.Parameters.Add("FSGAEND", OracleType.NVarChar).Value = dwData["FSGAEND"].ToString(); 
          or1.Parameters.Add("FSGNEUB", OracleType.NVarChar).Value = dwData["FSGNEUB"].ToString(); 
          or1.Parameters.Add("FSGNEUD", OracleType.NVarChar).Value = dwData["FSGNEUD"].ToString(); 
          or1.Parameters.Add("FSGABEZ", OracleType.NVarChar).Value = dwData["FSGABEZ"].ToString(); 
          or1.Parameters.Add("FSGLAENGE", OracleType.NVarChar).Value = dwData["FSGLAENGE"].ToString(); 
          or1.Parameters.Add("FSGLAEME", OracleType.NVarChar).Value = dwData["FSGLAEME"].ToString(); 
          or1.Parameters.Add("FSGLAEGRP", OracleType.NVarChar).Value = dwData["FSGLAEGRP"].ToString(); 
          or1.Parameters.Add("FSGLAEFKT", OracleType.NVarChar).Value = dwData["FSGLAEFKT"].ToString(); 
          or1.Parameters.Add("FSGBREITE", OracleType.NVarChar).Value = dwData["FSGBREITE"].ToString(); 
          or1.Parameters.Add("FSGBRTME", OracleType.NVarChar).Value = dwData["FSGBRTME"].ToString(); 
          or1.Parameters.Add("FSGBRTGRP", OracleType.NVarChar).Value = dwData["FSGBRTGRP"].ToString(); 
          or1.Parameters.Add("FSGBRTFKT", OracleType.NVarChar).Value = dwData["FSGBRTFKT"].ToString(); 
          or1.Parameters.Add("FSGHOEHE", OracleType.NVarChar).Value = dwData["FSGHOEHE"].ToString(); 
          or1.Parameters.Add("FSGHOEME", OracleType.NVarChar).Value = dwData["FSGHOEME"].ToString(); 
          or1.Parameters.Add("FSGHOEGRP", OracleType.NVarChar).Value = dwData["FSGHOEGRP"].ToString(); 
          or1.Parameters.Add("FSGHOEFKT", OracleType.NVarChar).Value = dwData["FSGHOEFKT"].ToString(); 
          or1.Parameters.Add("FSGGEW", OracleType.NVarChar).Value = dwData["FSGGEW"].ToString(); 
          or1.Parameters.Add("FSGGEWME", OracleType.NVarChar).Value = dwData["FSGGEWME"].ToString(); 
          or1.Parameters.Add("FSGGEWGRP", OracleType.NVarChar).Value = dwData["FSGGEWGRP"].ToString(); 
          or1.Parameters.Add("FSGGEWFKT", OracleType.NVarChar).Value = dwData["FSGGEWFKT"].ToString(); 
          or1.Parameters.Add("FSGMEGME", OracleType.NVarChar).Value = dwData["FSGMEGME"].ToString(); 
          or1.Parameters.Add("FSGMEGGRP", OracleType.NVarChar).Value = dwData["FSGMEGGRP"].ToString(); 
          or1.Parameters.Add("FSGMEGFKT", OracleType.NVarChar).Value = dwData["FSGMEGFKT"].ToString(); 
          or1.Parameters.Add("FSGVOL", OracleType.NVarChar).Value = dwData["FSGVOL"].ToString(); 
          or1.Parameters.Add("FSGPRGRP", OracleType.NVarChar).Value = dwData["FSGPRGRP"].ToString(); 
          or1.Parameters.Add("FSGGRLAUF", OracleType.NVarChar).Value = dwData["FSGGRLAUF"].ToString(); 
          or1.Parameters.Add("FSGZSFORM", OracleType.NVarChar).Value = dwData["FSGZSFORM"].ToString(); 
          or1.Parameters.Add("FSGARTKZ", OracleType.NVarChar).Value = dwData["FSGARTKZ"].ToString(); 
          or1.Parameters.Add("FSGFILLER", OracleType.NVarChar).Value = dwData["FSGFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
